﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using System;
using System.Collections.Concurrent;
using System.Threading.Tasks;

namespace Fast.Extensions.DatabaseAccessor.EntityFrameworkCore
{
    public interface IUnitOfWork
    {
        /// <summary>
        /// 上下文
        /// </summary>
        ConcurrentDictionary<Guid, DbContext> DbContexts { get; }
        /// <summary>
        /// 开启事务
        /// </summary>
        IDbContextTransaction Begin();

        /// <summary>
        /// 开启事务
        /// </summary>
        Task<IDbContextTransaction> BeginAsync();

        /// <summary>
        /// 提交事务
        /// </summary>
        void Commit();

        /// <summary>
        /// 提交事务
        /// </summary>
        /// <returns></returns>
        Task CommitAsync();

        /// <summary>
        /// 回滚事务
        /// </summary>
        void Rollback();

        /// <summary>
        /// 回滚事务
        /// </summary>
        Task RollbackAsync();
    }
}
